package com.example.smart.base.ui.fragment

import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.viewbinding.ViewBinding
import com.example.smart.base.dialog.LoadingDialog
import com.example.smart.base.utils.getViewBinding

abstract class BaseFragment<V : ViewBinding> : Fragment() {
    protected lateinit var binding: V

    private val loading by lazy {
        activity?.let {
            LoadingDialog(it)
        }
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        binding = getViewBinding(inflater, container)
        return binding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        initView(view)
        initListener()
    }

    override fun onResume() {
        super.onResume()
        loadData()
    }

    abstract fun initView(view: View)

    open fun initListener() {}

    private fun loadData() {
        canLoadData()
    }

    open fun canLoadData() {}

    open fun onFragmentResult(requestCode: Int, resultCode: Int, data: Intent?) {

    }
}